package com.zxkj.commonpatrol.adapt;

import android.media.MediaPlayer;

import androidx.fragment.app.FragmentManager;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.zxkj.commonpatrol.R;
import com.zxkj.commonpatrol.utils.MediaManager;
import com.zxkj.commonpatrol.view.VioceDialog;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class PlayVioceAdapt  extends BaseQuickAdapter<String, BaseViewHolder> {
    public FragmentManager getSupportFragmentManager;
    public PlayVioceAdapt(int layoutResId, @Nullable List<String> data, FragmentManager getSupportFragmentManager) {
        super(layoutResId, data);
        this.getSupportFragmentManager=getSupportFragmentManager;
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, @Nullable String s) {
        baseViewHolder.setText(R.id.tv,"錄音"+baseViewHolder.getLayoutPosition()+1);

        baseViewHolder.itemView.findViewById(R.id.cl).setOnClickListener(v -> {
            VioceDialog vioceDialog = VioceDialog.getInstance();
            vioceDialog.show(getSupportFragmentManager, "");

            MediaManager.playSound(s, new MediaPlayer.OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer mediaPlayer) {
                    vioceDialog.dismiss();

                }
            });
        });
    }
}
